/*
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';

import '../../../../data/controllers/${ObjectName}_controller.dart';
import '../../../../data/remote/database_helper.dart';
import '../models/${ObjectName}.dart';

part '${NAME}_state.dart';
part '${NAME}_event.dart';

class ${ClassName}Cubit extends Bloc<${ClassName}Event,${ClassName}State> {
  ${ClassName}Cubit(${ClassName}State ${ObjectName}sInitial) : super(${ObjectName}sInitial) {
    on<${ClassName}InitialEvent>(_onInitialize);
    // for add player
    on<Add${ModelName}LoadingTapEvent>(_onAdd${ModelName}Loading);
    on<Add${ModelName}FailedTapEvent>(_onAdd${ModelName}Failed);
    on<Add${ModelName}SuccessTapEvent>(_onAdd${ModelName}Success);
    // for update player
    on<Update${ModelName}LoadingEvent>(_onUpdate${ModelName}Loading);
    on<Update${ModelName}FailedEvent>(_onUpdate${ModelName}Failed);
    on<Update${ModelName}SuccessEvent>(_onUpdate${ModelName}Success);
    //for delete player
    on<Delete${ModelName}LoadingEvent>(_onDelete${ModelName}Loading);
    on<Delete${ModelName}FailedEvent>(_onDelete${ModelName}Failed);
    on<Delete${ModelName}SuccessEvent>(_onDelete${ModelName}Success);
    on<ChangeSelectMode>(_onChangeSelectMod);
    on<ChangeSelectedItem>(_onChangeSelectedItem);
    on<TabSelectAll>(_onTabSelectAll);
  }
  static ${ClassName}Cubit get(context) => BlocProvider.of(context);



  TextEditingController searchBox = TextEditingController();

  List<${ModelName}> all${ModelName}s = [];
  List<${ModelName}> selected${ModelName}s = [];
  List<${ModelName}> ${ObjectName}s = [];



  bool searchFlag = false;
  bool selectedMode = false;

  _onInitialize(
    ${ClassName}InitialEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    searchBox.clear();
    emit(${ClassName}Loading());
    await ${ModelName}Controller.getMy${ModelName}s().catchError((e){
      emit(${ClassName}Error());
      return null;
    }).then((value)async{
      if(value != null && value.state) {
        ${ObjectName}s = List<${ModelName}>.generate(value.data.length, (index) => ${ModelName}.fromJson(value.data[index]));
        all${ModelName}s = ${ObjectName}s.where((e)=>true).toList();
        localeMyData();
        emit(${ClassName}Done());
      }else if(value != null){
        var res = await DatabaseHelper.getAll${ModelName}s();
        ${ObjectName}s = List<${ModelName}>.generate(res.length, (index) => ${ModelName}.fromJson(res[index]));
        all${ModelName}s = ${ObjectName}s.where((e)=>true).toList();
        emit(${ClassName}Done());
      }else{
        if (kDebugMode) {
          print('value is null');
        }
        emit(${ClassName}Loading());
        var res = await DatabaseHelper.getAll${ModelName}s();
        ${ObjectName}s = List<${ModelName}>.generate(res.length, (index) => ${ModelName}.fromJson(res[index]));
        all${ModelName}s = ${ObjectName}s.where((e)=>true).toList();
        emit(${ClassName}Done());
      }
    });
  }
  _onAdd${ModelName}Success(
      Add${ModelName}SuccessTapEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    ${ObjectName}s.add(event.${ObjectName});
    all${ModelName}s.add(event.${ObjectName});
    emit(${ClassName}Update());
  }
  _onAdd${ModelName}Failed(
      Add${ModelName}FailedTapEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
  }
  _onAdd${ModelName}Loading(
      Add${ModelName}LoadingTapEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    print("جاري اضافة لاعب");
  }

  _onUpdate${ModelName}Success(
      Update${ModelName}SuccessEvent event,
      Emitter<${ClassName}State> emit,
      ) async {

    for(int i =0 ;i<${ObjectName}s.length;i++){
      if(${ObjectName}s[i].${ObjectName}Id == event.${ObjectName}.${ObjectName}Id){
        ${ObjectName}s[i]= event.${ObjectName};
      }

    }
    emit(${ClassName}Update());
  }
  _onUpdate${ModelName}Failed(
      Update${ModelName}FailedEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
  }

  _onUpdate${ModelName}Loading(
      Update${ModelName}LoadingEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    print("جاري تحديث لاعب");
  }
  _onDelete${ModelName}Success(
      Delete${ModelName}SuccessEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    ${ObjectName}s.removeWhere((e)=>e.${ObjectName}Id == event.${ObjectName}Id);
    emit(${ClassName}Update());
  }
  _onDelete${ModelName}Failed(
      Delete${ModelName}FailedEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
  }
  _onDelete${ModelName}Loading(
      Delete${ModelName}LoadingEvent event,
      Emitter<${ClassName}State> emit,
      ) async {
    print("جاري تحديث لاعب");
  }
  _onChangeSelectMod(
      ChangeSelectMode event,
      Emitter<${ClassName}State> emit,
      ) async {
    selectedMode = event.mod;
    print(event.mod);
    emit(${ClassName}Update());
  }

  _onChangeSelectedItem(
      ChangeSelectedItem event,
      Emitter<${ClassName}State> emit,
      ) async {
    if(event.value){
      selected${ModelName}s.add(event.${ObjectName});
    }else{
      selected${ModelName}s.remove(event.${ObjectName});
    }
  }
  _onTabSelectAll(
      TabSelectAll event,
      Emitter<${ClassName}State> emit,
      ) async {
    if(event.value == true) {
      for (${ModelName} ${ObjectName} in ${ObjectName}s) {
        selected${ModelName}s.add(${ObjectName});
      }
    }else{
      for (${ModelName} ${ObjectName} in ${ObjectName}s) {
        selected${ModelName}s.remove(${ObjectName});
      }
    }
    emit(SelectAll${ModelName}sState(value: event.value));
  }
  localeMyData()async{
    for(int i=0;i<all${ModelName}s.length;i++) {
      await DatabaseHelper.insert${ModelName}( all${ModelName}s[i].toJsonLocale()).then((value){

      }).catchError((e) {
        print("اللاعب موجود");
      });
    }
  }


  onSearchTap(){
    print(searchFlag);
    searchFlag = !searchFlag;
    emit(${ClassName}Update());
  }
  onSearch(String text){
    if(text.isEmpty){
      ${ObjectName}s = all${ModelName}s.where((e)=>true).toList();
    }else {
      ${ObjectName}s = all${ModelName}s.where(
            (element) =>element.name?.contains(text)==true,
      ).toList();
    }
    emit(${ClassName}Update());
  }

}
*/
